package pl.plesken.xml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class ConfigParser {
	
	private Properties properties = new Properties();
	
	public String readConf(String key) {
		try {
			FileInputStream in = new FileInputStream("conf/GUI.xml");
			System.setProperty("file.encoding", "UTF-8");
			properties.loadFromXML(in);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
		} 
        return properties.getProperty(key);
	}
	
	public void saveConf(String key, String value, String file) {
		try {
			FileOutputStream out = new FileOutputStream(file);
            properties.setProperty(key, value);
            properties.storeToXML(out, null);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
		}
	}
	
}